using System;
using System.Diagnostics;
using System.Globalization;

namespace Atomic.Libraries.Physics.Units
{
	[Serializable]
	[DebuggerDisplay("{DebuggerDisplay}")]
	public class PerTemperature : IQuantity
	{
		private double value;

		private PerTemperature(double value)
		{
			this.value = value;
		}

		public static PerTemperature FromUnit(IUnitSystem system, double value)
		{
			return new PerTemperature(value / (1.0 / system.TemperatureScaling));
		}

		public static PerTemperature FromPerKelvin(double value)
		{
			return FromUnit(UnitSystem.AtomicSystem, value);
		}

		public double ToUnit(IUnitSystem system)
		{
			return value * (1.0 / system.TemperatureScaling);
		}

		public double ToPerKelvin()
		{
			return ToUnit(UnitSystem.InternationalSystem);
		}

		public static implicit operator double(PerTemperature value)
		{
			return value.ToPerKelvin();
		}

		public static implicit operator PerTemperature(double value)
		{
			return FromPerKelvin(value);
		}

		private string DebuggerDisplay
		{
			get
			{
				return string.Format(CultureInfo.InvariantCulture, "{0} K^-1", ToPerKelvin());
			}
		}
	}
}
